import random
total = 0
print("\nCreator: Brain-Bacon [Phear The Ceal and John Weddington]")
print("Example Input: '2d4 1d6 3d20' OR 'q' to quit")

while True:
	rolls = input('\nInput dice rolls seperated by spaces: ').split()
	#check for quit

	#check to make sure that input is actually there
	if len(rolls) < 1:
		continue

	if rolls[0].lower() == 'q':
		exit()
		
	#seperate individual YdX inputs
	for roll in range(len(rolls)):
		if rolls[roll][0] == 'd':
			rolls[roll] = '1' + rolls[roll]
		rolls[roll] = rolls[roll].split('d')
		
	#go through each roll and add up total 
	for roll in rolls:
		addy, mult = '', 1
		for count in range(int(roll[0])):
			if '+' in roll[1]:
				foo = roll[1].split('+')
				roll.insert(1, foo[0])
				total += int(foo[1])
				addy = '+' + foo[1]
				del roll[2]
			if '*' in roll[1]:
				foo = roll[1].split('*')
				roll.insert(1, foo[0])
				mult = int(foo[1])
				addy = '*'  + str(foo[1])
				del roll[2]
				
			try:
				total += random.randint(1, int(roll[1]))
			except ValueError: #in case of input of positve followed by negative
				total = 0
		#then print the results
		print('Results for', 'd'.join(roll) + addy, 'is', total*mult)
		total = 0
